/*
 * StringCase.cpp
 *
 *  Created on: 2012-9-7
 *      Author: yangentao@gmail.com
 */
#include "test.h"

#include "../src/yet/String.h"
using namespace  yet;
using namespace std;

TEST(String, conductor1) {
	String s;
	EXPECT_TRUE(s.empty());
}
TEST(String, conductor2) {
	String s1("abc");
	EXPECT_TRUE(s1.equals("abc")) << ", " << s1.size() << "[" << s1.cString() << "]";
}

TEST(String, conductor4) {
	String s1("abc", 2);
	EXPECT_TRUE(s1.equals("ab"));
}

TEST(String, destructor1) {

	String* s = new String();
	delete s;
	GTEST_SUCCEED();
}

TEST(String, assign) {
	String s("abc");
	String s2 = s;
	EXPECT_NE(s.bufferR(), s2.bufferR());
	EXPECT_TRUE(s2.equals(s));

	s = "01234567890123456789";
	s2 = s;
	EXPECT_EQ(s.bufferR(), s2.bufferR());
	EXPECT_TRUE(s2.equals(s));
}

TEST(String, assign2) {
	String s("abc");
	String s2 = s;
	s2.set(0, 'A');
	EXPECT_NE(s.bufferR(), s2.bufferR());
	EXPECT_FALSE(s2.equals(s));
}

TEST(String, append1) {
	String s;
	s.append('a');
	s.append("bc");
	s.append("def", 3);
	EXPECT_TRUE(s.equals("abcdef")) << "test equals";
}

TEST(String, insert1) {
	String s;
	s.insert(0, "abc");
	s.insert(1, "BC");
	EXPECT_TRUE(s.equals("aBCbc"));
}
TEST(String, insert2) {
	String s;
	s.insert(0, "abc");
	s.insert(0, "BC");
	EXPECT_TRUE(s.equals("BCabc"));
}
TEST(String, insert3) {
	String s;
	s.insert(0, "abc");
	s.insert(3, "BC");
	EXPECT_TRUE(s.equals("abcBC"));
}

TEST(String, remove1) {
	String s = "abcde";
	s.remove(0);
	EXPECT_TRUE(s.equals("bcde"));
}
TEST(String, remove2) {
	String s = "abcde";
	s.remove(1);
	EXPECT_TRUE(s.equals("acde"));
}
TEST(String, remove3) {
	String s = "abcde";
	s.remove(4);
	EXPECT_TRUE(s.equals("abcd"));
}

TEST(String, remove4) {
	String s = "abcde";
	s.remove(0, 2);
	EXPECT_TRUE(s.equals("cde"));
}
TEST(String, remove5) {
	String s = "abcde";
	s.remove(1, 2);
	EXPECT_TRUE(s.equals("ade"));
}
TEST(String, remove6) {
	String s = "abcde";
	s.remove(3, 2);
	EXPECT_TRUE(s.equals("abc"));
}

TEST(String, subString1) {
	String s = "abcde";
	String s2 = s.subString(0, 2);
	EXPECT_TRUE(s2.equals("ab"));
}
TEST(String, subString2) {
	String s = "abcde";
	String s2 = s.subString(0, 5);
	EXPECT_TRUE(s2.equals("abcde"));
}
TEST(String, subString3) {
	String s = "abcde";
	String s2 = s.subString(1, 2);
	EXPECT_TRUE(s2.equals("bc"));
}
TEST(String, subString4) {
	String s = "abcde";
	String s2 = s.subString(3, 2);
	EXPECT_TRUE(s2.equals("de"));
}
//TEST(String, subString5) {
//	String s = "abcde";
//	ASSERT_ANY_THROW(s.subString(4, 2));
//}

TEST(String, subString6) {
	String s = "abcde";
	String s2 = s.subString(4);
	EXPECT_TRUE(s2.equals("e"));
}

TEST(String, replace1) {
	String s = "abc";
	s.replace(1, 1, "B");
	EXPECT_TRUE(s.equals("aBc"));
}

TEST(String, replace2) {
	String s = "abc";
	s.replace(0, 2, "B");
	EXPECT_TRUE(s.equals("Bc"));
}
TEST(String, replace3) {
	String s = "abc";
	s.replace(1, 2, "B");
	EXPECT_TRUE(s.equals("aB"));
}
TEST(String, replace4) {
	String s = "abc";
	s.replace(0, 3, "B");
	EXPECT_TRUE(s.equals("B"));
}
TEST(String, replace5) {
	String s = "abc";
	s.replace(0, 3, "");
	EXPECT_TRUE(s.equals(""));
}
TEST(String, replace6) {
	String s = "abc";
	s.replace(0, 0, "");
	EXPECT_TRUE(s.equals("abc"));
}

TEST(String, startWith1) {
	String s = "abc";
	EXPECT_TRUE(s.startWith(0));
	EXPECT_TRUE(s.startWith(""));
	EXPECT_TRUE(s.startWith("a"));
	EXPECT_TRUE(s.startWith("ab"));
	EXPECT_TRUE(s.startWith("abc"));

	EXPECT_FALSE(s.startWith("c"));
	EXPECT_FALSE(s.startWith("bc"));
	EXPECT_FALSE(s.startWith("abcd"));

}
TEST(String, startWith2) {
	String s = "abc";
	EXPECT_TRUE(s.startWith("", 0));
	EXPECT_TRUE(s.startWith("a", 1));
	EXPECT_TRUE(s.startWith("ab", 2));
	EXPECT_TRUE(s.startWith("abc", 3));
	EXPECT_TRUE(s.startWith("abcd", 3));
	EXPECT_TRUE(s.startWith("abcde", 3));

	EXPECT_FALSE(s.startWith("c", 1));
	EXPECT_FALSE(s.startWith("bc", 2));
	EXPECT_FALSE(s.startWith("abcd", 4));
}
TEST(String, startWith3) {
	String s = "abc";
	EXPECT_TRUE(s.startWith(String("")));
	EXPECT_TRUE(s.startWith(String("a")));
	EXPECT_TRUE(s.startWith(String("ab")));
	EXPECT_TRUE(s.startWith(String("abc")));

	EXPECT_FALSE(s.startWith(String("c")));
	EXPECT_FALSE(s.startWith(String("bc")));
	EXPECT_FALSE(s.startWith(String("abcd")));
}

TEST(String, endWith1) {
	String s = "abc";
	EXPECT_TRUE(s.endWith(""));
	EXPECT_TRUE(s.endWith("c"));
	EXPECT_TRUE(s.endWith("bc"));
	EXPECT_TRUE(s.endWith("abc"));

	EXPECT_FALSE(s.endWith("xabc"));
	EXPECT_FALSE(s.endWith("ab"));

}
TEST(String, endWith2) {
	String s = "abc";
	EXPECT_TRUE(s.endWith("", 0));
	EXPECT_TRUE(s.endWith("c", 1));
	EXPECT_TRUE(s.endWith("bc", 2));
	EXPECT_TRUE(s.endWith("abc", 3));

	EXPECT_FALSE(s.endWith("xabc", 4));
	EXPECT_FALSE(s.endWith("ab", 2));
}
TEST(String, endWith3) {
	String s = "abc";
	EXPECT_TRUE(s.endWith(String("")));
	EXPECT_TRUE(s.endWith(String("c")));
	EXPECT_TRUE(s.endWith(String("bc")));
	EXPECT_TRUE(s.endWith(String("abc")));

	EXPECT_FALSE(s.endWith(String("xabc")));
	EXPECT_FALSE(s.endWith(String("ab")));
}

TEST(String, endWith4) {
	String s = "abc";
	EXPECT_TRUE(s.endWith(String("")));
	EXPECT_TRUE(s.endWith(String("c")));
	EXPECT_TRUE(s.endWith(String("bc")));
	EXPECT_TRUE(s.endWith(String("abc")));

	EXPECT_FALSE(s.endWith(String("xabc")));
	EXPECT_FALSE(s.endWith(String("ab")));
}
TEST(String, endWith5) {
	String s = "abc";
	EXPECT_TRUE(s.endWith(String("")));
}
TEST(String, endWith6) {
	String s = "abc";
	EXPECT_TRUE(s.endWith(String("c")));
}
TEST(String, endWith7) {
	String s = "abc";
	EXPECT_TRUE(s.endWith(String("bc")));
}
TEST(String, endWith8) {
	String s = "abc";
	EXPECT_TRUE(s.endWith(String("abc")));
}
TEST(String, endWith9) {
	String s = "abc";
	EXPECT_FALSE(s.endWith(String("xabc")));
}
TEST(String, endWith10) {
	String s = "abc";
	EXPECT_FALSE(s.endWith(String("ab")));
}

